<?php
/**
 * Created by JetBrains PhpStorm.
 * User: deadlinehlt
 * Date: 13-6-14
 * Time: 下午4:59
 * To change this template use File | Settings | File Templates.
 */
include_once "./../application/helper/Util.php";
include_once "./../application/models/ActivityArtProfile.php";
include_once "./../application/models/ActivityReportProfile.php";

class ActivityController extends Zend_Controller_Action
{
    var $activityModle;
    var $reportModel;

    public function init()
    {
        //session_start();
        /* Initialize action controller here */
        $this->activityModle = new ActivityArtProfile();
        $this->reportModel = new ActivityReportProfile();

    }

    public function indexAction()
    {
    }

    public function showAction(){
        if(!isset($_SESSION['user'])) $this->_redirect("/");
        if(isset($_GET['type'])) $type = $_GET['type'];
        if(isset($_GET['id'])) $id = $_GET['id'];

        $detailInfo = $this->activityModle->getActivityInfo($id);
        $this->view->controller = 'activity';
        $this->view->action = 'play';
        $this->view->type = $type;
        $this->view->detailInfo = $detailInfo;

    }

    public function showreportAction(){
        if(!isset($_SESSION['user'])) $this->_redirect("/");
        if(isset($_GET['id'])) $id = $_GET['id'];

        $detailInfo = $this->reportModel->getActivityInfo($id);
        $this->view->controller = 'activity';
        $this->view->action = 'report';
        $this->view->detailInfo = $detailInfo;
    }

    public function playAction(){

        if(!isset($_SESSION['user'])) $this->_redirect("/");
        $type = 'all';
        $page = 1;
        $per = 5;
        if(isset($_GET['type'])) $type = $_GET['type'];
        if(isset($_GET['page'])) $page = $_GET['page'];
        if(isset($_GET['per'])) $per = $_GET['per'];

        $allList = $this->activityModle->getActivityList(1, $type);
        $allNum = count($allList);

        $resultList = array();
        $startNum = ($page-1)*$per;

        for($i = $startNum,$j = 0; $i < $allNum && $j < $per; $i++,$j++){
            $resultList[] = $allList[$i];
        }

        /* Initialize action controller here */
        $this->view->sepHtml = getSepHtml('/activity/play?type='.$type,$allNum,$page,$per);
        //print_r($this->view->sepHtml);
        $this->view->controller = 'activity';
        $this->view->action = 'play';
        $this->view->type = $type;
        $this->view->resultList = $resultList;
    }

    public function reportAction(){

        if(!isset($_SESSION['user'])) $this->_redirect("/");
        $type = 'all';
        $page = 1;
        $per = 5;
        if(isset($_GET['type'])) $type = $_GET['type'];
        if(isset($_GET['page'])) $page = $_GET['page'];
        if(isset($_GET['per'])) $per = $_GET['per'];

        $allList =  $this->reportModel->getActivityList($type);
        $allNum = count($allList);

        $resultList = array();
        $startNum = ($page-1)*$per;

        for($i = $startNum,$j = 0; $i < $allNum && $j < $per; $i++,$j++){
            $resultList[] = $allList[$i];
        }

        /* Initialize action controller here */
        $this->view->sepHtml = getSepHtml('/activity/report?type='.$type,$allNum,$page,$per);
        //print_r($this->view->sepHtml);
        $this->view->controller = 'activity';
        $this->view->action = 'report';
        $this->view->type = $type;
        $this->view->resultList = $resultList;
    }

    public function publishAction(){
        if(!isset($_SESSION['user'])) $this->_redirect("/");
        $edit_type = 'new';
        $id = '-1';
        /* Initialize action controller here */
        if(isset($_GET['edit_type']) && isset($_GET["id"])) {
            $edit_type = $_GET['edit_type'];
            $id=$_GET['id'];
            //$this->_redirect("http://www.baidu.com");
        }

        if($edit_type == 'new' || $edit_type == 'modify')
        {
            $this->view->edit_type = $edit_type;
            $this->view->id= $id;
        }
        else if($edit_type == 'save')
        {
            //$this->_redirect("http://www.google.com");
            if(isset($_POST['formhash']) && $_POST['formhash']=='aa9ddf38')
            {
                $new_modify = $_POST['new_modify'];
                $article_id = $_POST['article_id'];
                $classid = $_POST['classid'];
                $title = $_POST['title'];
                $place = $_POST['place'];
                $time_1 = $_POST['time_1'];
                $time_1 = $time_1.' '.$_POST['hour'].':'.$_POST['minute'].':00';
                $artist = $_POST['artist'];
                $report_reporter = $_POST['report_reporter'];
                $report_compere = $_POST['report_compere'];
                $report_reporter_descrip = $_POST['report_reporter_descrip'];
                $price = $_POST['price'];
                $ticket_time = $_POST['time_2'].' '.$_POST['hour_sale'].':'.$_POST['minute_sale'].':00';
                $ticket_status = $_POST['ticket_status'];
                $ticket_place = $_POST['ticket_place'];
                $sponsor = $_POST[''] = $_POST['sponsor'];
                $duration = $_POST['duration'];
                $link = $_POST['link'];
                $label = $_POST['label'];
                $detail = $_POST['detail'];

                $publisher = $_SESSION['user'];

                if($classid == "1" || $classid == 2)
                {
                    $this->activityModle->publishArtActivity($new_modify, $article_id, $classid, $title, $place, $time_1,$artist, $report_reporter, $report_compere, $report_reporter_descrip,
                        $price, $ticket_time, $ticket_status, $ticket_place, $sponsor, $duration,$link, $label, $detail, $publisher );
                    $this->_redirect("/activity/play?type=all");
                }

            }
        }


    }


}